package co2.bean;

import java.io.Serializable;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import co2.engine.BeanGetter;
import co2.engine.DAOInterface;
import co2.pojos.MstUser;

@ManagedBean
@ViewScoped
public class ConfirmationBean extends AbstractBean implements Serializable {
	private static final long serialVersionUID = 1L;

	private boolean confirmed;
	
	@Autowired
	@Qualifier("daoI")
	private DAOInterface dao;
	
	@PostConstruct
	public void postCon(){
		try{
			
			Map map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			String userId = map.get("userId").toString();
			String uuid = map.get("uuid").toString();
			MstUser user = (MstUser) dao.get(MstUser.class, userId);
			if(user!=null && user.getUuid().equals(uuid)){
				user.setStatus("ACTIVE");
				dao.update(user);
				confirmed = true;
			}else{
				confirmed = false;
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public boolean isConfirmed() {
		return confirmed;
	}
	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}
	public DAOInterface getDao() {
		return dao;
	}
	public void setDao(DAOInterface dao) {
		this.dao = dao;
	}
}
